package java8_16;
import  java.util.*;
/**
 * @author oldliu
 * @since 1.0
 */
public class OnlineStore {
    public static void main(String[] args) {
        String []foods=new String[3]; //菜名
        double[] price=new double[3]; //菜价
        String name[]=new String[6]; //客户姓名
        int num[]=new int[6];        //所定份数
        // String info[]=new String[6]; //菜品信息
        String time[]=new String[6]; //送餐时间
        String address[]=new String[6]; //送餐地址
        int state[]=new int[6];  //送餐状态
        double sumPrice[]=new double[6]; //全部消费
        int good[]=new int[3]; //点赞数
        double foodnum[]=new double[6]; //所定份数
        int foodID[]=new int[6]; //菜品编码
        foods[0]="红烧带鱼";
        price[0]=38;
        good[0]=0;
        foodID[0]=1;//
        foods[1]="鱼香肉丝";
        price[1]=20;
        good[1]=0;
        foodID[1]=2;
        foods[2]="时令鲜蔬";
        price[2]=10;
        good[2]=0;
        foodID[2]=3;
        //
        name[0]="张晴";
        name[1]="张晴";
        //
//        info[0]="红烧带鱼";
//        info[1]="鱼香肉丝";

        //
        num[0]=2;
        num[1]=2;
        //
        time[0]="3";
        time[1]="10";
        //
        address[0]="天虎路207号";
        address[1]="天虎路207号";
        //
        state[0]=1;
        state[1]=0;
        //
        sumPrice[0]=76;
        sumPrice[1]=46;
        //
        foodnum[0]=2;
        foodnum[1]=2;

        System.out.println("欢迎使用\"吃货联盟订单系统\"");
        System.out.println("***********************");
        int ch=0;
        while (true){
            System.out.println("1:我要订餐");
            System.out.println("2:查看餐袋");
            System.out.println("3:签收订单");
            System.out.println("4:删除订单");
            System.out.println("5:我要点赞");
            System.out.println("6:退出系统");
            System.out.println("***********************");
            System.out.println("请选择");
            Scanner in=new Scanner(System.in);
            ch=in.nextInt();
            switch(ch){
                case 1:
                    System.out.println("***我要订餐***");
                    System.out.println("请输入订餐人姓名");
                    int index=0;
                    for(index=0;index<name.length;index++){
                        if(name[index]==null){
                            break;
                        }
                    }
                    name[index]=in.next();
                    System.out.println("序号   菜名    单价   点赞数");
                    for(int i=0;i<foods.length;i++){
                        System.out.println((i+1)+"    "+foods[i]+"  "+price[i]+"    "+good[i]);
                    }
                    System.out.println("请选择你要点的菜品编码：");
                    foodID[index]=in.nextInt();
                    System.out.println("请选择你要点的份数：");
                    foodnum[index]=in.nextDouble();
                    System.out.println("请输入送餐时间10-20点间整点送菜：");
                    time[index]=in.next();
                    int timesongcan=Integer.parseInt(time[index]);
                    System.out.println("请输入送地址：");
                    address[index]=in.next();
                    System.out.println("订餐成功！");
                    System.out.println("您定的是:"+foods[foodID[index]-1]+" "+foodnum[index]+"份");
                    if(timesongcan>=10&&timesongcan<=20) {
                        System.out.println("送餐时间:" + time[index]);
                    }else {
                        System.out.println("抱歉，您预定的时间无法送餐，系统将自动分配送餐时间");
                        time[index]="12";
                        System.out.println("送餐时间更正为:" + time[index]);
                    }
                    //越界
                    sumPrice[index]=price[foodID[index]-1]*foodnum[index];
                    double songcanfei=0;
                    if(sumPrice[index]<50){
                        songcanfei=5;
                        sumPrice[index]+=5;
                    }
                    double zongji=sumPrice[index]+songcanfei;
                    System.out.println("餐费:"+sumPrice[index]+",送餐费："+songcanfei +"，总计："+zongji);
                    break;



                case 2:
                    for(int i=0;i<name.length;i++){
                        if(!(name[i]==null)){
                            System.out.println("序号"+(i+1));
                            System.out.println("订餐人:"+name[i]);
                            System.out.println("餐品信息:"+foods[foodID[i]-1]+" "+foodnum[i]+"份");//要改
                            System.out.println("送餐日期:"+time[i]);
                            System.out.println("订餐地址:"+address[i]);
                            System.out.println("总消费:"+sumPrice[i]);
                            System.out.println("订单状态:"+state[i]);
                            System.out.println("");
                        }else{
                            break;
                        }
                    }
                    break;

                case 3:
                    System.out.println("***签收订单***");
                    System.out.println("请选择要签收的订单序号：");
                    int ordernum=in.nextInt();
                    if(ordernum>name.length){
                        System.out.println("输入了无效订单号，无法签收");
                        break;
                    }else if(name[ordernum-1]==null){
                        System.out.println("顾客姓名为空，订单不存在，无法签收");
                        break;
                    }else if(state[ordernum-1]==1){
                        System.out.println("订单已经签收，无法执行");
                        break;
                    }else{
                        state[ordernum-1]=1;
                        System.out.println("您的订单已成功签收！");
                    }
                    break;

                case 4:
                    System.out.println("***删除订单***");
                    System.out.println("请输入要删除的订单序号：");
                    int orderdelete=in.nextInt();
                    if(orderdelete>name.length){
                        System.out.println("输入了无效序号");
                        break;
                    }else if(name[orderdelete-1]==null){
                        System.out.println("该订单不存在");
                        break;
                    }else if(state[orderdelete-1]==0) {
                        System.out.println("该订单未签收，无法删除!");
                        break;
                    }else if(name[orderdelete]==null){
                        name[orderdelete-1]=null;
                        time[orderdelete-1]=null;
                        address[orderdelete-1]=null;
                        foodnum[orderdelete-1]=-1;
                        foodID[orderdelete-1]=-1;
                        state[orderdelete-1]=0;
                        sumPrice[orderdelete-1]=-1;
                        System.out.println("删除成功！");
                        break;
                    }
                    else{
                        for(int i=orderdelete-1;i<name.length-1;i++){
                            name[i]=name[i+1];
//                             price[i]=price[i+1];
                            time[i]=time[i+1];
                            address[i]=address[i+1];
                            foodnum[i]=foodnum[i+1];
                            foodID[i]=foodID[i+1];
                            state[i]=state[i+1];
                            sumPrice[i]=sumPrice[i+1];
                        }
                        name[name.length-1]=null;
                        time[name.length-1]=null;
                        address[name.length-1]=null;
                        foodnum[name.length-1]=-1;
                        foodID[name.length-1]=-1;
                        state[name.length-1]=0;
                        sumPrice[name.length-1]=-1;
                        System.out.println("删除成功！");
                        break;

                    }
                case 5:
                    System.out.println("***我要点赞***");
                    System.out.println("序号   菜名    单价   点赞数");
                    for(int i=0;i<foods.length;i++){
                        System.out.println((i+1)+"    "+foods[i]+"  "+price[i]+"    "+good[i]);
                    }
                    System.out.println("请输入你要点赞的菜品：");
                    int foodzan=in.nextInt();
                    if(foodzan>=1&&foodzan<=foods.length) {
                        good[foodzan - 1] += 1;
                        System.out.println("点赞成功！");
                        break;
                    }else{
                        System.out.println("抱歉，这个餐品不存在哦");
                        break;
                    }
                case 6:
                    return;
                default:
                    System.out.println("抱歉，你输入的指令不存在，请重试");
                    break;

            }

        }

//        //找到下一个空位置
//        int index=0;
//        for(index=0;index<name.length;index++){
//            if(name[index]==null){
//                break;
//            }
//        }
//        System.out.println("找到了第一个空位置："+index);
//        String[]a5={"小狗","老六","小猫","小熊","小🐟","老虎"};
//        Scanner in=new Scanner(System.in);
//        System.out.println("请输入要删除的位置：");
//        int k=in.nextInt();
//        //k到最后一个，往前移动一位
//        for(int i=k;i<a5.length-1;i++){
//            a5[i]=a5[i+1];
//        }
//        a5[a5.length-1]=null;
//        System.out.println(Arrays.toString(a5));


    }
}
